package com.zh.authority.dao;

import javacommon.base.*;
import cn.org.rapid_framework.page.*;
import com.zh.authority.model.*;
import com.zh.authority.vo.query.*;
import static cn.org.rapid_framework.util.ObjectUtils.*;
import org.springframework.stereotype.Repository;
/**
 * @author grey2 email:grey2@126.com
 * @version 1.0
 * @since 1.0
 */
@SuppressWarnings("unchecked")
@Repository
public class RoleDao extends BaseHibernateDao<Role,java.lang.Integer>{

	public Class getEntityClass() {
		return Role.class;
	}
	
	public Page findPage(RoleQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
		String sql = "select t from Role t where 1=1 "
			  	+ "/~ and t.roleName = {roleName} ~/"
			  	+ "/~ and t.url = {url} ~/"
				+ "/~ order by [sortColumns] ~/";

        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
        StringBuilder sql2 = new StringBuilder("select t from Role t where 1=1 ");
        if(isNotEmpty(query.getId())) {
            sql2.append(" and  t.id = :id ");
        }
        if(isNotEmpty(query.getRoleName())) {
            sql2.append(" and  t.roleName = :roleName ");
        }
        if(isNotEmpty(query.getUrl())) {
            sql2.append(" and  t.url = :url ");
        }
        if(isNotEmpty(query.getSortColumns())) {
            sql2.append(" order by :sortColumns ");
        }	
        
		return pageQuery(sql,query);
	}
	

}
